<?php
function index_content($category)
{
global $category;
global $page;

if ($category == "")
{
	$query_all = "SELECT vic FROM vicove ORDER BY vic_id DESC";
	$result_all = mysql_query($query_all);
	if(!$result_all){die(mysql_error());}
	$num_rows_all = mysql_num_rows($result_all);
}
else 
{
	$query_all = "SELECT vic FROM vicove WHERE category='$category' ORDER BY vic_id desc";
	$result_all = mysql_query($query_all);
	$num_rows_all = mysql_num_rows($result_all);
}	

	$max = 10;
	$limit = $max*$page;
	$max_pages = ceil($num_rows_all/$max);

for ($start_from = 0; $start_from < $limit; $start_from += $max) 
	{
	
		if ($category == "")
		{
			$query = "SELECT * FROM vicove ORDER BY vic_id DESC LIMIT ".$start_from.", ".$max."";
			$result = mysql_query($query);
			$num_rows = mysql_num_rows($result);
		}
		else
		{
			$query = "SELECT * FROM vicove WHERE category='$category' ORDER BY vic_id DESC LIMIT ".$start_from.", ".$max."";
			$result = mysql_query($query);
			$num_rows = mysql_num_rows($result);
		}
	}
	
	if ($num_rows == "0") { echo "Няма резултати!"; }
	else 
	{
		for ($i = 0; $i < $num_rows; $i++)
		{
			$row = mysql_fetch_array($result);
			
			$vic_id = $row["vic_id"];
			$category = $row["category"];
			$category = ucfirst($category);
			$category_len = strlen($category);
			$vic = $row["vic"];
			$vic = ucfirst($vic);
			$vic_len = strlen($vic);
			$date = $row["date"];
			$show_date = date("H:i:s d.m.Y", $date);

			if ( $vic_len > 0 && $category_len > 0)
			{		
?>
			<div class="post">
			<!-- <h2 class="title"><a href="#">Welcome to Collaboration</a></h2> -->
			<div class="entry">
				<p><?php echo $vic;?></p>
				
				<!-- Facebook Button BEGIN 
				<div style="float:left;">
				<a name="fb_share" type="icon_link" share_url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>">Сподели</a>
				<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
				</div>
				 Facebook Button END -->
				
				<div style="float:left;">
				<span class="st_facebook" st_url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" ></span>
				<span class="st_twitter" st_url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" ></span>
				<span class="st_googleplus" st_url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" ></span>
				</div>
				
				<!-- Svejo Button BEGIN 
				<div style="float:right;">
				<a href="http://svejo.net/submit/?url=http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" data-url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" data-type="compact" id=" svejo-button">Добави в Svejo</a>
				<script type="text/javascript" src="http://svejo.net/javascripts/svejo-button.js"></script>
				</div>
				 Svejo Button END -->
			</div>
			<p class="meta"><span class="posted">Категория <a href="index.php?category=<?php echo $category;?>"><?php echo $category;?></a> публикуван на: <?php echo $show_date;?></span> <!--<a href="#" class="permalink">Read more</a> <a href="#" class="comments">Comments (18)</a>--> </p>
			</div>
<?php
			}
		}


			
		
		
									echo "<div clas=\"pagination\" align=\"center\"><br />";
											// -- STRANICIRANETO --
											$prev_page = $page-1;
											$next_page = $page+1;
											$page_3_min = $page-3;
											$page_2_min = $page-2;
											$page_1_min = $page-1;
											$page_1_plus = $page+1;
											$page_2_plus = $page+2;
											$page_3_plus = $page+3;

											if ($page <= 1) {echo "<span> &lt;&lt; </span><span> &lt; </span>";}
											else 
											{
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=1' category='Първа страница'> &lt;&lt; </a></span>";
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=$prev_page' category='Предишна страница'> &lt; </a></span>";
											}
											if ($page_3_min > 0)
											{
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=$page_3_min'> $page_3_min </a></span>";
											}
											if ($page_2_min > 0)
											{
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=$page_2_min'> $page_2_min </a></span>";
											}
											if ($page_1_min > 0)
											{
											echo " <span><a href='index.php?category=".$_GET["category"]."&page=$page_1_min'> $page_1_min </a></span> ";
											}
											
											echo  "<strong><span>$page</span></strong>";
											
											if ($page_1_plus <= $max_pages)
											{
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=$page_1_plus'> $page_1_plus </a></span>";
											}
											if ($page_2_plus <= $max_pages)
											{
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=$page_2_plus'> $page_2_plus </a></span>";
											}
											if ($page_3_plus <= $max_pages)
											{
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=$page_3_plus'> $page_3_plus </a></span>";
											}
											
											if ($page == $max_pages) echo "<span> &gt; </span><span> &gt;&gt; </span>";
											else
											{
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=$next_page' category='Следваща страница'> &gt; </a></span>";
											echo "<span><a href='index.php?category=".$_GET["category"]."&page=$max_pages' category='Последна страница'> &gt;&gt; </a></span>";
											}

	}
										?>
											<!--<span>Първа</span>
											<span>Предишна</span>
											<strong><span>1</span></strong>
											<strong><a href="#" category="2">2</a></strong>
											<a href="#" category="Следваща">Следваща</a>
											<a href="#" category="Последна">Последна</a> -->	
										<br /><br />
										Страница <?php echo $page;?> от <?php echo $max_pages;?>	
									</div>
<?php 
}


function categories()
{

global $page;

	$query = "SELECT * FROM vicove GROUP BY category";
	$result = mysql_query($query);
	$num_rows = mysql_num_rows($result);
	
	if ($num_rows == "0") { echo "Няма резултати!"; }
	else 
	{
		for ($i = 0; $i < $num_rows; $i++)
		{
			$row = mysql_fetch_array($result);
			
			$category = $row["category"];
			$category = ucfirst($category);
			$category_len = strlen($category);

			if ($category_len > 0)
			{	
				if (isset($_GET["category"]) && $_GET["category"]==$category)
				{
					echo "<a href=\"index.php?category=$category\"><li id=\"current\">$category</li></a>";
				}
				else
				{
					echo "<a href=\"index.php?category=$category\"><li>$category</li></a>";
				}
			}
		}
	}
	
}

function vic($vic_id)
{
$vic_id = $_GET["vic_id"];

$query = "SELECT * FROM vicove WHERE vic_id='$vic_id'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);

if ($num_rows == "0") { echo "Няма резултати!"; }
	else 
	{
			$row = mysql_fetch_array($result);
			
			$vic_id = $row["vic_id"];
			$category = $row["category"];
			$category = ucfirst($category);
			$category_len = strlen($category);
			$vic = $row["vic"];
			$vic = ucfirst($vic);
			$vic_len = strlen($vic);
			$date = $row["date"];
			$show_date = date("H:i:s d.m.Y", $date);

			if ( $vic_len > 0 && $category_len > 0)
			{		
?>
			<div class="post">
			<!-- <h2 class="title"><a href="#">Welcome to Collaboration</a></h2> -->
			<div class="entry">
				<p><?php echo $vic;?></p>
				
				<!-- Facebook Button BEGIN
				<a name="fb_share" type="icon_link" share_url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>">Сподели</a>
				<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
				Facebook Button END -->
				
				<div style="float:left;">
				<span class="st_facebook" st_url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" ></span>
				<span class="st_twitter" st_url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" ></span>
				<span class="st_googleplus" st_url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" ></span>
				</div>
				
				<!-- Svejo Button BEGIN 
				<div style="float:right;">
				<a href="http://svejo.net/submit/?url=http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" data-url="http://www.posmeise.com?vic_id=<?php echo $vic_id; ?>" data-type="compact" id="svejo-button">Добави в Svejo</a>
				<script type="text/javascript" src="http://svejo.net/javascripts/svejo-button.js"></script>
				</div>
				 Svejo Button END -->
			</div>
			<p class="meta"><span class="posted">Категория <a href="#"><?php echo $category;?></a> публикуван на: <?php echo $show_date;?></span> <!--<a href="#" class="permalink">Read more</a> <a href="#" class="comments">Comments (18)</a>--> </p>
			</div>
<?php
		}
}

}

function meta_tags($description="", $keywords="", $charset="utf-8")
{
	$return = "<meta http-equiv=\"content-type\" content=\"text/html; charset=".$charset."\" />\n";
	if ($description != "")
	{
		$return .= "<meta name=\"description\" content=\"".$description."\" />\n";
	}
	if ($keywords != "")
	{
		$return .= "<meta name=\"keywords\" content=\"".$keywords."\" />\n";
	}
	$return .= "<meta name=\"robots\" content=\"index, follow\" />
<meta name=\"googlebot\" content=\"noarchive\" />
<meta name=\"classification\" content=\"internet\" />
<meta name=\"revisit-after\" content=\"20 days\" />
<meta http-equiv=\"expires\" content=\"0\" />
<meta http-equiv=\"cache-control\" content=\"no-cache\" />
<meta http-equiv=\"pragma\" content=\"no-cache\" />
<meta http-equiv=\"content-language\" content=\"bg\" />
<meta name=\"copyright\" content=\"Copyright &copy; 2012 Nimex, All rights reserved.\" />
<meta name=\"distribution\" content=\"global\" />
<meta name=\"rating\" content=\"general\" />
<meta name=\"pubdate\" content=\"2011-02-07\" />";
	return $return;
}

function vic_text($vic_id)
{

$query = "SELECT * FROM vicove WHERE vic_id='$vic_id'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);

if ($num_rows == "0") { echo "Няма резултати!"; }
	else 
	{
		$row = mysql_fetch_array($result);
		
		$vic_id = $row["vic_id"];
		$category = $row["category"];
		$category = ucfirst($category);
		$category_len = strlen($category);
		$vic = $row["vic"];
		$vic = stripslashes($vic);
		$vic = str_replace("<br>","",$vic);
		$vic = ucfirst($vic);
		$vic_len = strlen($vic);
		$date = $row["date"];
		$show_date = date("H:i:s d.m.Y", $date);

		if ( $vic_len > 0 )
		{		
			return $vic;
		}
	}

}

function sakra6tenie($var, $max_simbols)
{
	if (strlen($var) > $max_simbols)
	{
		return nl2br(substr($var, 0, $max_simbols))."...";
	}
	else
	{
		return nl2br($var);
	}
}
?>